package com.example.njut;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class AlertDialogActivity extends AppCompatActivity {
    private Button t1;
    private Button t2;
    private Button t3;
    private Button t4;
    private Button t5;
    String xz;


    private TextView text1;
    private TextView text2;
    private TextView text3;

    String star[] = {"射手座","处女座","水瓶座","金牛座","狮子座"};
    String hob[] = {"吃饭","睡觉","打游戏","发呆","其它"};
    boolean hobChoice[] = {false,false,false,false,false};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_dialog);

        t1 = (Button) findViewById(R.id.t1);
        t2 = (Button) findViewById(R.id.t2);
        t3 = (Button) findViewById(R.id.t3);
        t4 = (Button) findViewById(R.id.t4);
        t5 = (Button) findViewById(R.id.t5);
        text1 = (TextView) findViewById(R.id.text1);
        text2 = (TextView) findViewById(R.id.text2);
        text3 = (TextView) findViewById(R.id.text3);

        t1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(AlertDialogActivity.this);
                ab.setIcon(R.mipmap.logo);
                ab.setTitle("警告！");
                ab.setMessage("是否退出！");
                ab.create().show();
            }
        });

        t2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(AlertDialogActivity.this);
                ab.setIcon(R.mipmap.logo);
                ab.setTitle("警告！");
                ab.setMessage("是否退出！");
                ab.setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //finish();
                        //System.exit(0);
                        android.os.Process.killProcess( android.os.Process.myPid());
                    }
                });
                ab.setNegativeButton("否", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(AlertDialogActivity.this,"Ohhhhhhhh",Toast.LENGTH_SHORT).show();
                    }
                });
                ab.create().show();
            }
        });

        t3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(AlertDialogActivity.this);
                ab.setIcon(R.mipmap.logo);
                ab.setTitle("选择你的星座：");
                ab.setItems(star, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        text1.setText(star[i]);
                    }
                });
                ab.create().show();
            }
        });

        t4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(AlertDialogActivity.this);
                ab.setIcon(R.mipmap.logo);
                ab.setTitle("选择你的星座：");
                ab.setSingleChoiceItems(star,-1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        xz = star[i];
                    }
                });
                ab.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        text2.setText(xz);
                    }
                });
                ab.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                ab.create().show();
            }
        });

        t5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab = new AlertDialog.Builder(AlertDialogActivity.this);
                ab.setIcon(R.mipmap.logo);
                ab.setTitle("选择你的爱好：");
                ab.setMultiChoiceItems(hob, hobChoice, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i, boolean b) {
                        hobChoice[i] = b;
                    }
                });
                ab.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String ah = "";
                        for(int ii=0;ii<hobChoice.length;ii++){
                            if(hobChoice[ii]==true){
                                ah = ah+hob[ii]+" ";
                            }
                        }
                        text3.setText(ah);
                    }
                });
                ab.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                ab.create().show();
            }
        });
    }
}
